<template>
  <div class="classify-top">
    <img
      src="http://81.68.133.139:3000/images/classify/1.png"
      alt=""
      @click="goback"
    />
    <van-search
      v-model="value"
      placeholder="搜索宠物商品"
      @click="gotoSerach"
    />
  </div>
  <div class="classify-box">
    <van-sidebar v-model="activeKey">
      <van-sidebar-item
        v-for="(item, index) in list"
        :key="item"
        :title="item"
        @click="changlist(index)"
      />
    </van-sidebar>
    <div class="classify-list">
      <img
        src="http://81.68.133.139:3000/images/store/banner2.png"
        alt=""
        class="classify-list-banner"
      />
      <div class="classify-list-box">
        <van-nav-bar :left-text="list2">
          <template #right>
            查看更多
            <van-icon name="arrow" size="18" />
          </template>
        </van-nav-bar>
        <ul>
          <li v-for="item in list1" :key="item">
            <img :src="item.imgUrl" alt="" />
            <p>{{ item.tabTitle }}</p>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";

export default {
  data() {
    return {
      value: "",
      list: ["猫咪主粮", "猫咪零食", "猫砂厕所"],
      activeKey: 0,
      list1: [],
      list2: "猫咪主粮",
    };
  },
  async created() {
    //列表参数获取获取
    await this.getList();
    this.list1 = this.tlist;
    console.log(this.tlist, "5");
  },
  computed: {
    ...mapState("logreg", ["tlist"]), //获取tlist
  },
  methods: {
    gotoSerach() {
      this.$router.push("/search/");
    },
    async changlist(index) {
      await this.getList(index + 1);
      this.list1 = this.tlist;
      this.list2 = this.list[index]; //控制查看更多左边的字体
    },
    goback() {
      this.$router.go(-1);
    },
    ...mapActions("logreg", ["getList"]),
  },
};
</script>

<style lang="less">
body {
  background: #fff;
}
.van-search__content {
  background: #fff !important;
  .van-badge__wrapper {
    font-size: 20px;
    color: rgb(226, 226, 226);
  }
}
.van-sidebar-item--select::before {
  background-color: transparent;
}
.van-sidebar {
  a:hover {
    font-weight: bold;
  }
}
.van-sidebar-item--select {
  font-weight: bold;
  color: black !important;
}
.van-sidebar-item {
  color: rgb(185, 185, 185);
  padding-right: 5px;
}
.classify-top {
  display: flex;
  img {
    height: 20px;
    width: 13px;
    margin: 15px;
  }
  .van-search {
    flex: 1;
  }
}
.classify-list {
  height: 100%;
  position: fixed;
  top: 47px;
  left: 80px;
  padding: 10px;
}
.classify-list-banner {
  height: 100px;
  width: 100%;
}
.van-nav-bar__right {
  padding-right: 0;
  color: rgb(171, 171, 173);
  .van-icon-arrow {
    color: rgb(171, 171, 173);
    opacity: 0.5;
    font-size: 10px;
  }
}
.van-nav-bar {
  &::after {
    border: 0;
  }
}
.van-nav-bar__left {
  padding-left: 0;
  .van-nav-bar__text {
    color: black;
    font-weight: bold;
  }
}
.classify-list-box {
  ul {
    display: flex;
    flex-wrap: wrap;
    li {
      height: 100px;
      width: 25%;
      margin: 10px;
      img {
        height: 80px;
        width: 80%;
        margin: 0 10%;
      }
      P {
        color: rgb(171, 171, 173);
        font-size: 10px;
        text-align: center;
      }
    }
  }
}
</style>
